package Cy.Servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Cy.DAO.CommodityDAO;
import Factory.CommodityFactory;
import extend.SelectCommodity2;

/**
 * Servlet implementation class SelectCommodity2Servlet
 */
@WebServlet("/selectcommodity2")
public class SelectCommodity2Servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private CommodityDAO commodityDAO = CommodityFactory.createDAO();
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		int curpage = Integer.parseInt(request.getParameter("curpage"));
		int pagesize = Integer.parseInt(request.getParameter("pagesize"));
		List<SelectCommodity2> list = commodityDAO.selectcommodity2(curpage, pagesize);
		int total = commodityDAO.countdetailedcommodity();
		request.setAttribute("list", list);
		request.setAttribute("total", total);
		request.getRequestDispatcher("selectCommodity2.jsp").forward(request, response);
				
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		super.doGet(req, resp);
	}
}
